package demo;

import static demo.ActivitiApplication.OUTCOME_Q;
import javax.jms.JMSException;
import javax.jms.Session;
import javax.jms.TextMessage;
import org.activiti.engine.delegate.DelegateExecution;
import org.activiti.engine.delegate.JavaDelegate;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.jms.core.JmsTemplate;
import org.springframework.jms.core.MessageCreator;
import org.springframework.stereotype.Component;

/**
 *
 * @author brizat
 */
@Component(value = "jmsClient")
public class JSMSender implements JavaDelegate{

    @Autowired
    private JmsTemplate jmsTemplate;

    @Override
    public void execute(DelegateExecution delegate) throws Exception {
         MessageCreator messageCreator = (Session session) -> {
             TextMessage message = session.createTextMessage("BlaBla");
             message.setStringProperty("processInstanceId", delegate.getProcessInstanceId());
             return message;
         };
        jmsTemplate.send(OUTCOME_Q, messageCreator);
    }

}
